/**
 * A even easier method is find the minimum and maximum elments in the array,
 * then max - min - sizeOfArray + 1 will be the answer.
 */

/**
 * @author antonio081014
 * @since Feb 9, 2012, 8:05:26 AM
 */
import java.util.Arrays;

public class DengklekTryingToSleep {
    public int minDucks(int[] ducks) {
        Arrays.sort(ducks);
        int count = 0;
        for (int i = 1; i < ducks.length; i++) {
            count += Math.abs(ducks[i] - ducks[i - 1] - 1);
        }
        return count;
    }

    // <%:testing-code%>
}
// Powered by [KawigiEdit] 2.0!

